"""
添加客户关怀
"""
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
#定位器
name_locator = (By.NAME, "name")
password_locator = (By.NAME, "password")
login_locator = (By.CSS_SELECTOR, "body > div.container > div > div.span4 > div > form > fieldset > input.btn.btn-primary")
kh_link_locator =(By.LINK_TEXT,"客户")
kh_khgh_locator = (By.LINK_TEXT,"客户关怀")
kh_khgh_xjgh_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(1) > div > a")
kh_khgl_kh_locator =(By.ID,"customer_name")
kh_khgl_lxr_locator =(By.ID,"contacts_name")
kh_khgl_ghzt_locator =(By.ID,"name")
kh_khgl_ghrq_locator =(By.ID,"care_time")
kh_khgl_bc_locator =(By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > thead > tr > td:nth-child(2) > input:nth-child(1)")
#数据
name = "admin"
password = "123456"
kh = "C4"
lxr = "胡雨龙"
ghzt = "生日快乐"
ghrq = "2023-04-27 17:20"

#操作
#打开浏览器
driver = webdriver.Chrome()
#最大化窗口
driver.maximize_window()
#进入悟空CRM登录界面
driver.get("http://192.168.1.25/crm/")
#输入用户名
driver.find_element(*name_locator).send_keys(name)
#输入密码
driver.find_element(*password_locator).send_keys(password)
#点击确定按钮
driver.find_element(*login_locator).click()
#点击线索按钮
driver.find_element(*kh_link_locator).click()
#点击客户关怀
driver.find_element(*kh_khgh_locator).click()
#点击新建客户
driver.find_element(*kh_khgh_xjgh_locator).click()
#输入客户
driver.find_element(*kh_khgl_kh_locator).send_keys(kh)
#输入联系人
driver.find_element(*kh_khgl_lxr_locator).send_keys(lxr)
#输入关怀主题
driver.find_element(*kh_khgl_ghzt_locator).send_keys(ghzt)
#输入关怀日期
driver.find_element(*kh_khgl_ghrq_locator).send_keys(ghrq)
#点击确定按钮
driver.find_element(*kh_khgl_bc_locator).click()
sleep(5)

if __name__ == '__main__':
    unittest.main()